package com.stgl.service;

import com.stgl.dao.BmqkDao;
import com.stgl.dao.SthdfdbDao;
import com.stgl.dao.WhkfdbDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class BmqkService {
    @Autowired
    private BmqkDao bmqkDao;

    @Autowired
    private WhkfdbDao whkfdbDao;

    @Autowired
    private SthdfdbDao sthdfdbDao;


    public List<Map<String,Object>>Search_bmqkNow(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=bmqkDao.Search_bmqkNow(gmap);
        for(int i=0;i<list1.size();i++){
            Map<String,Object>maps=list1.get(i);
            //查询社团收费项目
            List<Map<String,Object>>list2=whkfdbDao.Search_Whksf(maps);
            maps.put("whksf",list2);
            //查询社团教师
            List<Map<String,Object>>list3=whkfdbDao.Search_Whk_teacher(maps);
            maps.put("whkteas",list3);
            //查询该学生报名资料
            List<Map<String,Object>>list4=bmqkDao.Search_Bmzl(maps);
            maps.put("bmzl",list4);

            //查询该学生的缴费项目
            List<Map<String,Object>>list5=bmqkDao.Search_orderffee(maps);
            maps.put("jfxm",list5);
        }
        return list1;
    }


    public int bmqk_sh(Map<String,Object>gmap)
    {
        return bmqkDao.bmqk_sh(gmap);
    }





    public List<Map<String,Object>>Search_sthdbmqkNow(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=bmqkDao.Search_sthdbmqkNow(gmap);
        for(int i=0;i<list1.size();i++){
            Map<String,Object>maps=list1.get(i);
            //查询社团收费项目
            List<Map<String,Object>>list2=sthdfdbDao.Search_Stksf(maps);
            maps.put("stksf",list2);
            //查询社团教师
            List<Map<String,Object>>list3=sthdfdbDao.Search_Stk_teacher(maps);
            maps.put("stkteacher",list3);
            //查询该学生报名资料
            List<Map<String,Object>>list4=bmqkDao.Search_Bmzl(maps);
            maps.put("bmzl",list4);

            //查询该学生的缴费项目
            List<Map<String,Object>>list5=bmqkDao.Search_orderffee(maps);
            maps.put("jfxm",list5);
        }
        return list1;
    }



    public List<Map<String,Object>>export_bmqkNow(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=bmqkDao.Search_bmqkNow(gmap);
        return list1;
    }


    public List<Map<String,Object>>export_sthdbmqkNow(Map<String,Object>gmap)
    {
        List<Map<String,Object>>list1=bmqkDao.Search_sthdbmqkNow(gmap);
        return list1;
    }


    public int setjffs(Map<String,Object>gmap)
    {
        return bmqkDao.setjffs(gmap);
    }



    public Map<String,Object> del_bmqkBybid(Map<String,Object>gmap)
    {
        bmqkDao.del_orderfeeBybid(gmap);//删除订单的缴费项目
        bmqkDao.del_orderteaBybid(gmap);//删除订单的辅导教师
        bmqkDao.del_orderlistBybid(gmap);//删除订单
        bmqkDao.del_bmzlBybid(gmap);//删除报名情况资料
        bmqkDao.del_bmqkBybid(gmap);//删除报名情况
        Map<String,Object>rmap=new HashMap<String,Object>();
        rmap.put("msg","删除成功!");
        rmap.put("result",true);
        return rmap;
    }

    //调班功能
    public int updateStuBmqk(Map<String,Object>gmap)
    {
        return bmqkDao.updateStuBmqk(gmap);
    }
    public int updateOrderListByBid(Map<String,Object>gmap)
    {
        //先查询需要修改的报名的基本信息
        List<Map<String,Object>>list1=new ArrayList<>();
        list1=bmqkDao.getWhkDetailsByWid(gmap);
        if(list1.size()>0){
            String NJ=list1.get(0).get("NJ").toString();
            String BJ=list1.get(0).get("BJ").toString();
            String KM=list1.get(0).get("KM").toString();
            String MC=list1.get(0).get("MC").toString();
            String JJ=list1.get(0).get("JJ").toString();
            String FY=list1.get(0).get("FY").toString();
            Map<String,Object>smap=new HashMap<>();
            smap.put("nj",NJ);
            smap.put("bj",BJ);
            smap.put("km",KM);
            smap.put("mc",MC);
            smap.put("jj",JJ);
            smap.put("fy",FY);
            smap.put("bid",gmap.get("bid"));
            return bmqkDao.updateOrderListByBid(smap);
        }else{
            return 0;
        }
    }
    public void updateOrderTeaByWsid(Map<String,Object>gmap)
    {
        //根据bid 删除当前的授课教师
        bmqkDao.del_orderteaBybid(gmap);
        //查询相关教师
        List<Map<String,Object>>list1=new ArrayList<>();
        list1=bmqkDao.getteasByWid(gmap);
        //查询订单id
        Map<String,Object>ordermap=bmqkDao.orderdetailbybid(gmap);
        String oid=ordermap.get("OID").toString();
        //根据wsid插入新的教师
        for(int i=0;i<list1.size();i++){
            String otid = UUID.randomUUID().toString().replaceAll("-", "");
            String tname =list1.get(i).get("TNAME").toString();
            String jj =list1.get(i).get("JIANJIE").toString();
            Map<String,Object>smap=new HashMap<>();
            smap.put("otid",otid);
            smap.put("tname",tname);
            smap.put("jj",jj);
            smap.put("oid",oid);
            bmqkDao.insertOrderTeaByWsid(smap);
        }
    }



}
